import service from '@/utils/service'
import { IResult } from '@types'
import axios from 'axios'

export const getTokenFake = (data: Record<string, any>): Promise<IResult<any>> => {
  return service.post('/scy/login', data, {})
}

const token_api = '/scy/token/efficient'
export const getToken = (data): Promise<IResult<any>> => service.post(token_api, data) //获取真token

export const getInfo = (): Promise<IResult<any>> => service.get('/client/player/info', {}) //获取用户信息

const mgt_lottery = '/client/lottery'
export const getAllGameType = () => service.get(mgt_lottery + '/games', {}) //大厅列表

export const findTrendChart = (data) => service.get(mgt_lottery + '/findTrendChart', { params: data })

//开奖号码
let cancelToken = null
export const findCurrentWinNum = (params) => {
  if (cancelToken) {
    cancelToken?.cancel?.()
  }

  cancelToken = axios.CancelToken.source()

  return service.get(mgt_lottery + '/findCurrent', {
    params,
    cancelToken: cancelToken.token,
  })
}

export const findHistoryPage = (data) => service.post(mgt_lottery + '/findHistoryPage', data) // 开奖记录

export const cancelOrder = (data): Promise<IResult<any>> => service.get(mgt_lottery + '/cancel', { params: data }) //取消注单

export const cancelBatchOrder = (data): Promise<IResult<any>> => service.post(mgt_lottery + '/cancelBatch', data) //批量取消下单记录

export const findOrderPage = (data): Promise<IResult<any>> => service.post(mgt_lottery + '/findOrderPage', data) //下单记录

export const findRepetitionBet = (data) => service.get(mgt_lottery + '/findRepetitionBet', { params: data }) //找最近的投注记录

export const getHistoryMessages = (data) => service.post('/client/chat/history/list/v2', data)

export const getOtherUserBalance = (data) => service.get('/client/player/get/byId', { params: data })

export const getBetRules = (data) => service.get('/client/chat/rules', { params: data })

export const getLotteryTemplate = (data) => service.get(mgt_lottery + '/template', { params: data }) // 所有游戏模板

export const submitBetNow = (data): Promise<IResult<any>> => service.post(mgt_lottery + '/geGame', data) //下单

export const findOrderSum = (data) => service.post(mgt_lottery + '/findOrderSum', data) //投注总计

export const getCustomService = (): Promise<IResult<any>> => service.get('/client/player/getCustomService', {}) //获取客服列表
export const setBetPattern = (data): Promise<IResult<any>> => service.post(mgt_lottery + '/setBetPattern', data) //投注总计

export const findPlayMenu = (data) => service.get('/client/menu/findPlayMenu', { params: data }) //游戏玩法菜单

export const findOrderGroupPage = (data) => service.post(mgt_lottery + '/findOrderGroupPage', data) //投注记录(按分组)

export const getRuleDoc = (data): Promise<IResult<any>> => service.get('/client/doc/lottery', { params: data }) //获取彩票文案/规则
